#include "simplefocprotocol.h"
#include "simplefocparsepacket.h"
#include "simplefocsendpacket.h"
#include "simplefocfindpacket.h"

SimpleFOCProtocol::SimpleFOCProtocol(QObject *parent)
    : SimpleFOCProtocol(* new SimpleFOCProtocolData(), parent)
{

}

SimpleFOCProtocol::SimpleFOCProtocol(SimpleFOCProtocolData &data, QObject *parent)
    : BaseProtocol (data, parent)
{
    SimpleFOCParsePacket *parser = new SimpleFOCParsePacket(data, this);
    SimpleFOCSendPacket *sender = new SimpleFOCSendPacket(data, this);
    connect(sender, &BaseSendPacket::requestSend, this, &BaseProtocol::requestSend);

    connect(parser, &SimpleFOCParsePacket::receiveDebugData, this, &SimpleFOCProtocol::receiveDebugData);
    connect(parser, &SimpleFOCParsePacket::addGraphData, this, &SimpleFOCProtocol::addGraphData);

    data.m_parser = parser;
    data.m_sender = sender;
}

SimpleFOCProtocol::~SimpleFOCProtocol()
{
    delete m_d->m_sender;
    delete m_d->m_parser;
}

SimpleFOCSendPacket *SimpleFOCProtocol::getSender()
{
    return static_cast<SimpleFOCSendPacket*>(m_d->m_sender);
}
